﻿@{
    ViewBag.Title = "Administrator Control Panel";
}

<script src="/Scripts/MiscCommands.js"></script>

<br />
<br />
<h3><i>Adminstrator Control Panel</i></h3>
<table>
    <thead>
        <tr>
            <td>Request No.</td>
            <td>Request Type</td>
            <td>Request Size</td>
            <td>Associated Project</td>
            <td>User Requesting</td>
            <td>Approved?</td>
            <td>Actioned?</td>
            <td>Date Created</td>
            <td>Date Approved</td>
            <td>Date Actioned</td>
            <td> Action Request</td>
            <td>Comments</td>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in ViewBag.ListOfReqs)
        {
            <tr>
                <td>@item.RequestID</td>
                <td>@item.tblRequestType.strRequestName</td>
                <td>@item.intRequestSize GB</td>
                <td>
                    @{
            if (item.ProjectID != null)
            {
                ViewBag.AssocProj = item.Projects.strProjectName;
            }
            else
            {
                ViewBag.AssocProj = "None";
            }
                    }
                    @ViewBag.AssocProj
                </td>
                <td>@item.tblUser.strFirstName @item.tblUser.strLastName</td>
                <td>@{
            if (item.dtmApproved != null)
            {
                ViewBag.Approval = "yes";
            }
            else
            {
                ViewBag.Approval = "no";
            }
                    }@ViewBag.Approval</td>
                <td>@{
            if (item.dtmCompleted != null)
            {
                ViewBag.Actioned = "yes";
            }
            else
            {
                ViewBag.Actioned = "no";
            }
                }@ViewBag.Actioned</td>
                <td>@item.dtmCreated.ToString()</td>
                <td>@{
                    if(item.dtmApproved!=null)
                    {
                        ViewBag.dtmApproved = item.dtmApproved.ToString();
                    }else{
                        ViewBag.dtmApproved = "Not Approved";
                    }
                    }@ViewBag.dtmApproved</td>
                <td>@{
            if (item.dtmCompleted != null)
            {
                ViewBag.dtmCompleted = item.dtmCompleted.ToString();
            }
            else
            {
                ViewBag.dtmCompleted = "Not Actioned";
            }
}@ViewBag.dtmCompleted</td>   
                
                <td>
                    @{
            if (item.dtmCompleted == null)
            {
                //If the request hasnt been approved
                //Show a box, because this can be approved
                //Have this link and approve thre resource

                
                
                 <form action="/ControlPanel/actionStorage" method="post">
                     <input name="inputJob" value="@item.RequestID" type="hidden" />
                     <input type="submit" value="Action" />
                 </form>
                 
                 
                
            }


}
                </td>
                <td>
                    <div id="ModifyComment">
                        <form action="/ControlPanel/ModifyCommentAdmin" method="post">
                            <table align="center">
                                <tr>
                                    <td>
                                        <input name="theComment" type="text" style="width:100px" value="@item.Comments"> <input type="submit" value="Modify Comment" />
                                        <input name="theReq" type="hidden" value="@item.RequestID" />
                                    <td>
                                </tr>
                            </table>
                        </form>
                    </div> 
                </td>


                
                        
                                  
            </tr>
        }
        
    </tbody>
</table>

<br /><br /><br />

<div id="actionbuttons">
    <button onclick="adminChangePrimaryInv()">Change Primary Investigator</button> <button onclick="adminAddSchool()">Add A School</button>
    </form><button onclick="adminAddUser()">Add User</button> <button onclick="adminAddProject()">Add Project</button> <button onclick="adminRemoveUser()">Remove User</button> <button onclick="adminRemoveProject()">Remove Project</button>
</div>

<div id="AddUser" style="display:none">
    <h3><i>Create New User</i></h3>
    <form action="/ControlPanel/AdminAddUser" method="post">
        <div style="text-align:center; align-content:center">
            <table align="center">
                <tr>
                    <td>User Email:</td>
                    <td><input name="newUserName" type="text" /></td>
                </tr>
                <tr>
                    <td>User Password:</td>
                    <td><input name="newUserPassword" type="text" /></td>
                </tr>
                <tr>
                    <td>User First Name:</td>
                    <td><input name="newUserFirstName" type="text" /></td>
                </tr>
                <tr>
                    <td>User Last Name:</td>
                    <td><input name="newUserLastName" type="text" /></td>
                </tr>
                <tr>
                    <td>Department:</td>
                    <td>
                        <select name="newUserDepartmentID">

                            @foreach (var item in ViewBag.Departments)
                            {
                                <option value="@item.DepartmentID">@item.strDepartmentName</option>
                            }
                        </select>
                    </td>
                </tr>
                <tr>
                    <td> User Type:</td>
                    <td>
                        <select name="newUserTypeID">
                            @foreach (var item in ViewBag.UserTypes)
                            {
                                <option value="@item.UserTypeID">@item.strUserTypeName</option>
                            }

                        </select>
                    </td>
                </tr>
                <tr>
                    <td>

                    </td>
                    <td>
                        <input type="submit" value="Add" />
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>

<div id="AddProject" style="display:none">
    <h3><i>Add New Project</i></h3>
    <form action="/ControlPanel/AdminAddProject" method="post">
        <table align="center">
            <tr>
                <td>Project Name</td>
                <td><input type="text" name="newProjectName" /></td>
            </tr>
            <tr>
                <td>Project Owner</td>
                <td>
                    <select name="newProjectOwner">
                       @{
                            foreach (var item in ViewBag.Researchers)
                            {
                                <option value="@item.UserID">@item.strFirstName @item.strLastName</option>
                            }
                        }
                    </select>
                </td>
            </tr>
            <tr>
                <td>Project Initial Size (in Gigabytes)</td>
                <td><input type="text" name="newProjectSize" /></td>
            </tr>
            <tr><td></td><td><input type="submit" value="Add" /></td></tr>
        </table>
    </form>
</div>

<div id="RemoveUser" style="display:none">
    <h3><i>Remove User</i></h3><br />
    <p><i>Warning: Removing a user will delete all projects and requests associated with them</i></p><br />
    <form action="/ControlPanel/AdminRemoveUser" method="post">
        <table align="center">
            <tr>
                <td>Select User:</td>
                <td>
                    <select name="selectedUser">
                        @{
                            foreach (var item in ViewBag.Users)
                            {
                                <option value="@item.UserID">@item.strFirstName @item.strLastName : @item.tblUserType.strUserTypeName</option>
                            }
                        }
                    </select>
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Delete" /></td>
            </tr>
        </table>
    </form>
</div>

<div id="RemoveProject" style="display:none">
    <h3><i>Remove Project</i></h3><br />
    <p><i>Warning: Removing a project will delete all trace of it from the database.</i></p><br />
    <form action="/ControlPanel/AdminRemoveProject" method="post">
        <table align="center">
            <tr>
                <td>Select Project:</td>
                <td>
                    <select name="selectedProject">
                        @{
                            foreach(var item in ViewBag.Projects)
                            {
                                <option value="@item.ProjectID">@item.strProjectName</option>
                            }
                        }
                    </select>
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Delete" /></td>
            </tr>
        </table>
    </form>
</div>

<div id="ChangePrimaryInv" style="display:none">
    <h3><i>Change The Primary Investigator</i></h3><br />
    <form action="/ControlPanel/AdminChangePrimaryInv" method="post">
        <table align="center">
            <tr>
                <td>Select Project:</td>
                <td>
                    <select name="selectedProj">
                        @{
                            foreach (var item in ViewBag.Projects)
                            {
                                <option value="@item.ProjectID">@item.strProjectName Current Primary Investigator:@item.PI.strFirstName @item.PI.strLastName</option>
                            }
                        }
                    </select>
                </td>
            </tr>
            <tr>
                <td>Please Enter The New Primary Investigator</td>
                <td>
                <select name="newPrimaryInv">
                    @{
                        foreach (var item in ViewBag.Users)
                        {
                            <option value="@item.UserID">@item.strFirstName @item.strLastName</option>
                        }
                    }
                </select>
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Change" /></td>
            </tr>
        </table>
    </form>
</div>

<div id="AddSchool" style="display:none">
    <h3>
        <i>
            Add New School
        </i>
    </h3>
    <form action="/ControlPanel/AdminAddSchool" method="post">
        <table align="center">
            <tr>
                <td>
                    School Name
                </td>
                <td>
                    <input type="text" name="newSchoolName" />
                </td>
            </tr>
            <tr>
                <td>
                    School Approver's Email:
                </td>
                <td>
                    <input name="newUserName" type="text" />
                </td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><input name="newUserPassword" type="text" /></td>
            </tr>
            <tr>
                <td>User First Name:</td>
                <td><input name="newUserFirstName" type="text" /></td>
            </tr>
            <tr>
                <td>User Last Name:</td>
                <td><input name="newUserLastName" type="text" /></td>
            </tr>
            <tr>
                <td>
                    <input name="newUserTypeID" type="hidden" value=2>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="submit" value="Add" />
                </td>
            </tr>
        </table>
    </form>
</div>
